/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package org.teacup.eightdays.dao;

import static cn.org.rapid_framework.util.ObjectUtils.isNotEmpty;

import java.util.List;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;
import org.teacup.eightdays.common.BackIcon;
import org.teacup.eightdays.model.Orderinfo;
import org.teacup.eightdays.vo.query.OrderinfoQuery;

import cn.org.rapid_framework.page.Page;
/**
 * @author Abner email:521yexu2008(a)163.com
 * @version 1.0
 * @since 1.0
 */

@Repository
public class OrderinfoDao extends BaseHibernateDao<Orderinfo,java.lang.Long>{

	public Class getEntityClass() {
		return Orderinfo.class;
	}

	public List<Orderinfo> findWaitOrderinfos() {
		String sql = "select * from orderinfo where status = "
				+ BackIcon.OrderStatus.SUBSCRIBE;
		return getSession().createSQLQuery(sql).list();
	}

	public Page findPage(OrderinfoQuery query) {
        StringBuilder sqlBuilder = new StringBuilder("select t from Orderinfo t where 1=1 ");
        if(isNotEmpty(query.getOrderId())) {
            sqlBuilder.append(" and  t.orderId = :orderId ");
        }
        if(isNotEmpty(query.getMemberinfoId())) {
            sqlBuilder.append(" and  t.memberinfoId = :memberinfoId ");
        }
        if(isNotEmpty(query.getOrderNo())) {
            sqlBuilder.append(" and  t.orderNo = :orderNo ");
        }
        if(isNotEmpty(query.getOrderAmount())) {
            sqlBuilder.append(" and  t.orderAmount = :orderAmount ");
        }
        if(isNotEmpty(query.getStatus())) {
            sqlBuilder.append(" and  t.status = :status ");
        }
        if(isNotEmpty(query.getOrderTimeBegin())) {
            sqlBuilder.append(" and  t.orderTime >= :orderTimeBegin ");
        }
        if(isNotEmpty(query.getOrderTimeEnd())) {
            sqlBuilder.append(" and  t.orderTime <= :orderTimeEnd ");
        }
        if(isNotEmpty(query.getSchoolId())) {
            sqlBuilder.append(" and  t.schoolId = :schoolId ");
        }
        if(isNotEmpty(query.getMobileNo())) {
            sqlBuilder.append(" and  t.mobileNo = :mobileNo ");
        }
        if(isNotEmpty(query.getName())) {
            sqlBuilder.append(" and  t.name = :name ");
        }
        if(isNotEmpty(query.getAddress())) {
            sqlBuilder.append(" and  t.address = :address ");
        }
        if(isNotEmpty(query.getRemark())) {
            sqlBuilder.append(" and  t.remark = :remark ");
        }
        if(isNotEmpty(query.getBackRemark())) {
            sqlBuilder.append(" and  t.backRemark = :backRemark ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sqlBuilder.append(" order by :sortColumns ");
        }	
        String sql = sqlBuilder.toString();
		return pageQuery(sql,query);
	}
	

}